<template>
  <div>
      <h1>新增老师</h1>
      老师名字:<input type="text" v-model="teacher.teacherName"><br>  
      老师密码:<input type="password" v-model="teacher.pwd"><br>
      性别:<input type="radio" v-model="teacher.sex" value="男">男
           <input type="radio" v-model="teacher.sex" value="女">女<br>
      类型: <select v-model="teacher.typeId">
                <option value="">--请选择--</option>
                <option v-for="(type,index) in typeList" :key="index" :value="type.id">{{type.city}}</option>
            </select>
      
      <br>
      学校: <br>
      入职日期:<input type="date" v-model="teacher.hireDate"><br>
      薪资:<input type="number" v-model="teacher.salary"><br>
      备注:<input type="text" v-model="teacher.remark"><br>     
      <input type="button" value="新增" @click="add()">
  
  
  
  </div>
</template>

<script>
export default {
    data() {
        return {
            teacher:{
                sex:"女",
                typeId:"",//默认：--请选择--
            },//老师是一个对象
            typeList:[],//老师类型数组
        }
    },
    methods: {
        async add(){
            let res = await this.$http.post("/teacher",this.teacher)
            console.log(res)
            if(res.data.code==10000){
                alert("新增成功")
                this.$router.push("/teacherList")
            }else{
                alert("新增失败");
            }
        },
        //初始化老师类型的方法
        async initTypeList(){
            let res = await this.$http.get("/type/all")
            this.typeList = res.data.data
        }
    },
    created() {
        this.initTypeList()
    },
}
</script>

<style>

</style>